package com.kgc.good.goodmanagerweb.controller;

import com.kgc.good.bean.GoodAddress;
import com.kgc.good.bean.Goods;
import com.kgc.good.service.GoodAddressService;
import com.kgc.good.service.GoodsService;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class GoodsController {

    @Reference
    GoodsService goodsService;
    @Reference
    GoodAddressService goodAddressService;
    @RequestMapping("/seleGoodsaddress")
    public List<GoodAddress> seleGoodssaddress(){
        List<GoodAddress> all = goodAddressService.getAll();
        return all;
    }
    @RequestMapping("/seleByAddrId")
    public List<Goods> seleGoodsByAddress(@RequestParam(value = "district",required = false,defaultValue = "1")Integer district){
        List<Goods> goodsByAddress = goodsService.getGoodsByAddress(district);
        return goodsByAddress;
    }


    @RequestMapping("/seleById")
    public Goods seleById(Integer id){
        return goodsService.getById(id);
    }

    @RequestMapping("/upGoods")
    public String upGoods(@RequestBody Goods goods){
        Integer integer = goodsService.upGoods(goods);
        if(integer>0){
            return "SUCCESS";
        }
        return "FAIL";
    }



}
